//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    menuList: [{ id: '01', title: '近视', icon: '/images/s1.png', screeningStatus:1},
               { id: '02', title: '远视', icon: '/images/s2.png', screeningStatus: 0},
               { id: '03', title: '散光', icon: '/images/s3.png', screeningStatus: 1},
               { id: '04', title: '老花', icon: '/images/s4.png', screeningStatus: 0 },
               { id: '05', title: '斜视', icon: '/images/s5.png', screeningStatus: 0 },
               { id: '06', title: '弱视', icon: '/images/s6.png', screeningStatus: 0 },
               { id: '07', title: '色盲', icon: '/images/s7.png', screeningStatus: 1},
               { id: '08', title: '色弱', icon: '/images/s8.png', screeningStatus: 0 },
               { id: '09', title: '沙眼', icon: '/images/s9.png', screeningStatus: 0},
               { id: '010', title: '针眼', icon: '/images/s10.png', screeningStatus: 0 },
               { id: '011', title: '干眼症', icon: '/images/s11.png', screeningStatus: 0 },
               { id: '012', title: '视疲劳', icon: '/images/s12.png', screeningStatus: 0 },
               { id: '013', title: '飞蚊症', icon: '/images/s13.png', screeningStatus: 1 },
               { id: '014', title: '青光眼', icon: '/images/s14.png', screeningStatus: 0},
               { id: '015', title: '白内障', icon: '/images/s15.png', screeningStatus: 0},
               { id: '016', title: '夜盲症', icon: '/images/s16.png', screeningStatus: 0 },
               { id: '017', title: '结膜炎', icon: '/images/s17.png', screeningStatus: 0},
               { id: '018', title: '角膜炎', icon: '/images/s18.png', screeningStatus: 0},
               { id: '019', title: '视网膜病变', icon: '/images/s19.png', screeningStatus: 1 },
               { id: '020', title: '其他异常', icon: '/images/s20.png', screeningStatus: -1 }]             
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
